package com.buka.recipe.system.utils;

import com.buka.recipe.system.entity.Department;
import com.buka.recipe.system.entity.User;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserUtils {

    public static boolean isAdmin() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return "admin".equals(user.getUsername());
    }

    public static Integer getUserId() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return user.getId();
    }

    public static Department getDepartment() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return user.getDepartment();
    }

    public static String getDepartmentLevel() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (isAdmin()) {
            return "/";
        }
        return user.getDepartment().getLevel();
    }

}
